<template>
  <div v-if="partListCon">
    <!-- {{ activeBnnerIndex }}
    {{ partListCon }} -->
    <el-form ref="form" :model="partListCon" label-width="140px" size="small">
      <el-form-item label="是否显示">
        <el-switch
          class="zdySwith"
          :width="82"
          :value="partListCon.show"
          active-color="#13ce66"
          @change="updateInput($event, 'show')"
          inactive-color="#ffffff"
          active-text="显示"
          inactive-text="隐藏"
          active-value="1"
          inactive-value="0"
        ></el-switch>
      </el-form-item>
      <el-form-item label="标题">
        <el-input @input="updateInput($event, 'title')" :value="partListCon.title" placeholder="请输入标题"> </el-input>
      </el-form-item>
      <el-form-item label="副标题">
        <el-input @input="updateInput($event, 'title_en')" :value="partListCon.title_en" placeholder="请输入副标题"> </el-input>
      </el-form-item>
      <el-form-item label="根据定位查找商户">
        <el-switch
          class="zdySwith"
          :width="82"
          :value="partListCon.style"
          active-color="#13ce66"
          @change="updateInput($event, 'style')"
          inactive-color="#ffffff"
          active-text="是"
          inactive-text="否"
          active-value="1"
          inactive-value="0"
        ></el-switch>
      </el-form-item>
      <el-divider></el-divider>
      <el-form-item label="选择商户" v-if="partListCon.style == 0">
        <div class="supplierbox">
          <div class="supplier_item" v-for="(item, i) in partListCon.banner" :key="i">
            <a href="javascript:;" @click.prevent="delshopitem(item, i)" class="alert-delete del_supplier" title="隐藏">
              <i class="el-icon-close"></i>
            </a>
            <div class="supplier_item_left">
              <img :src="$fnc.getImgUrl(item.shop_logo + '')" alt="" />
            </div>
            <div class="supplier_item_content">
              <p>商户名称：{{ item.shop_title || "---" }}</p>
              <p>商户地址：{{ $fnc.deleteNumber(item.shop_province + item.shop_area) || "---" }}</p>
            </div>
          </div>
          <div class="supplier_item_add" @click.prevent="showDio">
            <i class="el-icon-plus"></i>
          </div>
        </div>
      </el-form-item>
    </el-form>

    <el-dialog title="选择商户" @close="closeshow" :lock-scroll="true" :append-to-body="true" :visible.sync="show" width="1200px" style="padding: 20px">
      <xzsupplier :show="xzshow" @isshow="closeshow" @sendShop="setId" :data="list.data" :isAddIden="false"></xzsupplier>
    </el-dialog>
  </div>
</template>

<script>
import uploadpic from "@/components/page/pic/up_pic";
import LinkMenu from "@/components/currency/Link_menu.vue";
import xzsupplier from "@/components/page/module/module_select/selsupplierbox";
import { mapState, mapGetters } from "vuex";
export default {
  data() {
    return {
      xzshow: false,
      currentPage1: 1,
      pageSize: 10,
      show: false,
      list: {
        data: [],
      },

      style_option: [
        {
          label: "一行1个",
          value: "0",
        },
        {
          label: "一行2个",
          value: "1",
        },
      ],
    };
  },

  computed: {
    ...mapGetters(["partListConConss"]),
    ...mapState({
      active: (state) => state.modulePage.active,
      activeBnnerIndex: (state) => state.modulePage.bannerNowIndex,
      allbanner: (state) => state.modulePage.allbanner,
      menulist: (state) => state.modulePage.menulist,
    }),
    partListCon() {
      if (this.activeBnnerIndex >= 0) {
        return this.allbanner[this.activeBnnerIndex];
      } else {
        return {};
      }
    },
  },
  components: {
    uploadpic,
    LinkMenu,
    xzsupplier,
  },
  created() {},
  mounted() {},
  methods: {
    delshopitem(item, index) {
      this.$store.commit("del_sonbanner_item", {
        key: this.activeBnnerIndex,
        index: index,
      });
      var val = this.partListCon.text.replace(item.id + "@", "");

      this.$store.commit("set_sonbanner_name", {
        key: this.activeBnnerIndex,
        name: "text",
        val: val,
      });
    },
    closeshow() {
      this.show = false;
      this.xzshow = false;
      // setTimeout(() => {
      //   this.show = false;
      // }, 100);
    },
    setId(row) {
      // this.show = false;
      // this.xzshow = false;
      console.log(row);
      var val = this.partListCon.text + row.id + "@";
      this.$store.commit("set_sonbanner_name", {
        key: this.activeBnnerIndex,
        name: "text",
        val: val,
      });
      this.$store.commit("addbanner_shopitem", {
        shop_title: row.shop_title,
        piclink: row.shop_logo,
        shop_province: row.shop_province,
        shop_area: row.shop_area,
      });
    },

    showDio() {
      this.show = true;
      setTimeout(() => {
        this.xzshow = true;
      }, 100);
    },
    del_banneritem(i) {
      this.$store.commit("del_sonbanner_item", {
        key: this.activeBnnerIndex,
        index: i,
      });
    },
    set_banneritem_val(pic, i, name) {
      this.$store.commit("set_sonbanner_item", {
        key: this.activeBnnerIndex,
        name: name,
        index: i,
        val: pic,
      });
    },

    toCheckArrIndex(i, status) {
      //排序

      var index2 = "";
      if (status == "up") {
        index2 = i - 1;
      } else {
        index2 = i + 1;
      }

      this.$store.commit("sortbanner_son", {
        key: this.activeBnnerIndex,
        index1: i,
        index2: index2,
        status: status,
      });
    },
    updateInput(val, name) {
      this.$store.commit("set_sonbanner_name", {
        key: this.activeBnnerIndex,
        name: name,
        val: val,
      });
    },

    getSendRow(row) {
      this.$store.dispatch("getShopsAll", { page: 1, page_size: 10 });
      var result = this.$fnc.getSendRow(row);
      var obj = {};
      obj.key = this.activeBnnerIndex;
      console.log(result);
      if (result.title != "自定义链接") {
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "desc",
          val: result.desc,
        });
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "links",
          val: result.links,
        });
      } else {
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "desc",
          val: "自定义链接",
        });
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "links",
          val: " ",
        });
      }
    },
  },
  watch: {},
};
</script>

<style scoped lang="less">
.supplierbox {
  width: 100%;
  display: flex;
  flex-flow: column;
  justify-content: flex-start;
  align-items: flex-start;

  .supplier_item_add {
    width: 100%;
    height: 50px;
    margin-top: 15px;
    background-color: #58b7fa;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    color: #ffffff;
    // width: 100%;
    // min-height: 50px;
    // padding: 10px 20px;
    // display: flex;
    // justify-content: center;
    // align-items: center;
    // background-color: #f0f0f0f0;
    // > i {
    //   font-size: 28px;
    //   color: #555555;
    //   font-weight: bold;
    // }
  }
  .supplier_item:hover .del_supplier {
    display: inline;
  }
  .supplier_item {
    width: 100%;
    position: relative;
    background-color: #f0f0f0;
    padding: 15px 20px;
    margin-bottom: 10px;
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-start;
    align-items: flex-start;
    margin-right: 10px;
    > a {
      font-size: 18px;
    }

    .del_supplier {
      position: absolute;
      right: 10px;
      top: 10px;
      font-size: 22px;
      display: none;
      cursor: pointer;
    }
    .supplier_item_left {
      width: 20%;
      margin-right: 10px;
      display: flex;
      justify-content: center;
      align-items: center;
      img {
        width: 100%;
      }
    }
    .supplier_item_content {
      display: flex;
      flex-flow: column;
      justify-content: flex-start;
      align-items: flex-start;
    }
  }
}
</style>
